/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AutenticacionElector.java
 *
 * Created on 11-ene-2013, 16:41:18
 */
package inscripciones.vista;

//import SecuGen.FDxSDK.jni.FDxDeviceInfoParam;
//import SecuGen.FDxSDK.jni.FDxDeviceName;
import inscripciones.DAO.ConsultasBD;
import inscripciones.Utiles.Mensajes;
import inscripciones.Utiles.Util;
import inscripciones.modelo.Participante;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
//import sisvoto.DAO.ConsultasBD;
//import sisvoto.Utiles.Mensajes;
//import sisvoto.Utiles.Util;
//import sisvoto.controlador.ValidacionFinger;
//import sisvoto.modelo.EleccionActual;
//import sisvoto.modelo.EleccionElector;
//import sisvoto.modelo.Elector;
//import sisvoto.modelo.HuellaDactilar;
//import sisvoto.modelo.VotantesEleccion;

/**
 *
 * @author DJ2-PC
 */
public class RegistroAsistencia extends javax.swing.JDialog {

    private Participante participante;
//    private Elector elector;
//    private JFPLib fplib = null;
//    private long ret;
//    private FDxDeviceInfoParam deviceInfo = new FDxDeviceInfoParam();
//    private long devicePort;
//    EleccionActual eleccionactual;

    /** Creates new form AutenticacionElector */
//    public AutenticacionElector(java.awt.Frame parent, boolean modal, EleccionActual eleccionactual) {
//        super(parent, modal);
////        this.elector = new Elector();
////        this.eleccionactual = eleccionactual;
//        initComponents();
//    }
    public RegistroAsistencia(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

//    public Elector getElector() {
//        return elector;
//    }
//
//    public void setElector(Elector elector) {
//        this.elector = elector;
//    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        imagePanel1 = new com.mycsistemas.swingec.panel.ImagePanel();
        curvesPanel1 = new com.mycsistemas.swingec.panel.CurvesPanel();
        jLblAutElector = new javax.swing.JLabel();
        jLblAutCedula = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        jLbAutNombrel = new javax.swing.JLabel();
        jLblAutApellido = new javax.swing.JLabel();
        jLblAutAnioEdu = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApellido = new javax.swing.JTextField();
        txtCategoria = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Autenticación Elector");
        setMinimumSize(new java.awt.Dimension(490, 340));

        imagePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/inscripciones/Recursos/''_10102012_1738.jpeg"))); // NOI18N

        curvesPanel1.setLayout(null);

        jLblAutElector.setFont(new java.awt.Font("Georgia", 3, 18));
        jLblAutElector.setForeground(new java.awt.Color(255, 255, 255));
        jLblAutElector.setText("Registro de Asistencia ");
        curvesPanel1.add(jLblAutElector);
        jLblAutElector.setBounds(120, 20, 290, 21);

        jLblAutCedula.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblAutCedula.setForeground(new java.awt.Color(255, 255, 255));
        jLblAutCedula.setText("Cédula: ");
        curvesPanel1.add(jLblAutCedula);
        jLblAutCedula.setBounds(40, 60, 100, 40);

        txtCedula.setFont(new java.awt.Font("Courier New", 1, 34));

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${participante.cedula}"), txtCedula, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCedulaActionPerformed(evt);
            }
        });
        txtCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCedulaKeyPressed(evt);
            }
        });
        curvesPanel1.add(txtCedula);
        txtCedula.setBounds(140, 60, 280, 40);

        jLbAutNombrel.setFont(new java.awt.Font("Elephant", 0, 14));
        jLbAutNombrel.setForeground(new java.awt.Color(255, 255, 255));
        jLbAutNombrel.setText("Nombres:");
        curvesPanel1.add(jLbAutNombrel);
        jLbAutNombrel.setBounds(40, 120, 100, 30);

        jLblAutApellido.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblAutApellido.setForeground(new java.awt.Color(255, 255, 255));
        jLblAutApellido.setText("Apellidos:");
        curvesPanel1.add(jLblAutApellido);
        jLblAutApellido.setBounds(40, 160, 100, 30);

        jLblAutAnioEdu.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblAutAnioEdu.setForeground(new java.awt.Color(255, 255, 255));
        jLblAutAnioEdu.setText("Categoria:");
        curvesPanel1.add(jLblAutAnioEdu);
        jLblAutAnioEdu.setBounds(40, 200, 90, 30);

        txtNombre.setEditable(false);
        txtNombre.setFont(new java.awt.Font("Franklin Gothic Medium", 1, 18));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${participante.nombre}"), txtNombre, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        curvesPanel1.add(txtNombre);
        txtNombre.setBounds(140, 120, 280, 30);

        txtApellido.setEditable(false);
        txtApellido.setFont(new java.awt.Font("Franklin Gothic Medium", 1, 18));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${participante.apellido}"), txtApellido, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        curvesPanel1.add(txtApellido);
        txtApellido.setBounds(140, 160, 280, 30);

        txtCategoria.setEditable(false);
        txtCategoria.setFont(new java.awt.Font("Franklin Gothic Medium", 1, 18));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${participante.categoria.nombre}"), txtCategoria, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        curvesPanel1.add(txtCategoria);
        txtCategoria.setBounds(140, 200, 280, 30);

        jLabel1.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Ingrese el número de Cédula y Presione Enter");
        curvesPanel1.add(jLabel1);
        jLabel1.setBounds(140, 100, 280, 14);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/inscripciones/Recursos/DeleteRed.png"))); // NOI18N
        jButton1.setText("Salir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton1KeyPressed(evt);
            }
        });
        curvesPanel1.add(jButton1);
        jButton1.setBounds(210, 260, 100, 40);

        javax.swing.GroupLayout imagePanel1Layout = new javax.swing.GroupLayout(imagePanel1);
        imagePanel1.setLayout(imagePanel1Layout);
        imagePanel1Layout.setHorizontalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(curvesPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
        );
        imagePanel1Layout.setVerticalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(curvesPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(imagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(imagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void txtCedulaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCedulaKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        if (!txtCedula.getText().isEmpty()) {
            if (new Util().esCedulaValida(txtCedula.getText())) {
                ArrayList<Participante> participantes = (ArrayList<Participante>) new ConsultasBD().buscarPOR("Participante", "cedula", "'" + txtCedula.getText() + "'");
                if (!participantes.isEmpty()) {
                    this.participante = participantes.get(0);
                    bindingGroup.unbind();
                    bindingGroup.bind();
                    new Mensajes().StandarTick(this, "Participante Registrado. \n   Bienvenido");
                    jButton1.requestFocus();
                } else {
                    this.participante = null;
                    new Mensajes().StandarWarning(this, "  Participante no Registrado. \n Consulte con el Administrador");
                    txtCedula.setText("");
//                            this.dispose();
                }


//                            this.elector = null;
//                            new Mensajes().StandarWarning(this, "Éste Elector No Puede Sufragar en Ésta Elección. \n        Consulte con el Administrador");
//                            this.dispose();
//                        }           

            } else {
                new Mensajes().StandarWarning(this, "Ingrese un Número de Cédula Valido");
                txtCedula.setText("");
            }
        } else {
            new Mensajes().StandarWarning(this, "Ingrese Número de Cédula");
        }


    }

//    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
//        if (!jTxtAutCedula.getText().isEmpty()) {
//            if (new Util().esCedulaValida(jTxtAutCedula.getText())) {
//                ArrayList<Elector> electores = (ArrayList<Elector>) new ConsultasBD().buscarPOR("Elector", "cedula", "'" + jTxtAutCedula.getText() + "'");
//                if (!electores.isEmpty()) {
//
//                    this.elector = electores.get(0);
//                    ArrayList<VotantesEleccion> votantes = (ArrayList<VotantesEleccion>) new ConsultasBD().buscarPOR2("VotantesEleccion", "elector", "'" + elector.getId() + "'", "eleccion", "'" + eleccionactual.getEleccion().getId() + "'");
//                    if (votantes.isEmpty()) {
//                        bindingGroup.unbind();
//                        bindingGroup.bind();
//                        jTxtAutParalelo.setText(elector.getAnioparalelo().getAnio().getNombre() + " " + elector.getAnioparalelo().getParalelo().getNombre());
//                        ArrayList<EleccionElector> elecelec = (ArrayList<EleccionElector>) new ConsultasBD().buscarPOR("EleccionElector", "elector", "'" + elector.getId() + "'");
//                        if (!elecelec.isEmpty()) {
//                            ArrayList<HuellaDactilar> huellas = (ArrayList<HuellaDactilar>) new ConsultasBD().buscarPOR("HuellaDactilar", "elector", "'" + elector.getId() + "'");
//                            if (huellas.size() == 2) {
//                                if (Configuracionfinger.getFplib() == null) {
//                                    conexionauxfinger();
//                                }
//                                ValidacionFinger vf = new ValidacionFinger(huellas, fplib, this, elector);
//                                vf.start();
//                            } else {
//                                new Mensajes().StandarWarning(this, "Aún no Ha Registrado Sus Huellas");
//                            }
//                        } else {
//                            this.elector = null;
//                            new Mensajes().StandarWarning(this, "Éste Elector No Puede Sufragar en Ésta Elección. \n        Consulte con el Administrador");
//                            this.dispose();
//                        }
//                    }else{
//                        new Mensajes().StandarWarning(this, "Éste Elector Ya Ha Ejercido El Voto");
//                        this.dispose();
//                    }
//                } else {
//                    new Mensajes().StandarWarning(this, "Éste Elector No está Registrado. \n   Consulte Con el Administrador");
//                }
//            } else {
//                new Mensajes().StandarWarning(this, "Verifique el Número de Cédula Ingresado");
//            }
//        } else {
//            new Mensajes().StandarWarning(this, "Ingrese Su Número de Cédula ");
//        }
//    }
}//GEN-LAST:event_txtCedulaKeyPressed

    private void txtCedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCedulaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCedulaActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
// TODO add your handling code here:
     if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
         this.dispose();
         RegistroAsistencia reg = new RegistroAsistencia(null, true);
         reg.setLocationRelativeTo(this);
         reg.setVisible(true);
         
     }

}//GEN-LAST:event_jButton1KeyPressed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.mycsistemas.swingec.panel.CurvesPanel curvesPanel1;
    private com.mycsistemas.swingec.panel.ImagePanel imagePanel1;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLbAutNombrel;
    private javax.swing.JLabel jLblAutAnioEdu;
    private javax.swing.JLabel jLblAutApellido;
    private javax.swing.JLabel jLblAutCedula;
    private javax.swing.JLabel jLblAutElector;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCategoria;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtNombre;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

//    private void conexionauxfinger() {
//        fplib = new JFPLib(FDxDeviceName.CN_FDU02);
//        devicePort = FDxPortAddr.AUTO_DETECT;
//        ret = fplib.openDevice(devicePort);
//        ret = fplib.getDeviceInfo(deviceInfo);
//        Configuracionfinger.setFplib(fplib);
//    }
    public Participante getParticipante() {
        return participante;
    }

    public void setParticipante(Participante participante) {
        this.participante = participante;
    }
}
